<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>BOM-定时器</title>
    <script type="text/javascript">
        var sid;

        function startT() {
            var today = new Date();
            var h = today.getHours();
            var m = today.getMinutes();
            var s = today.getSeconds();
            document.getElementById("time").value = "现在时间为：" + h + ":" + m + ":" + s;
            sid = setTimeout("startT()", 500);
        }

        function stopT() {
            clearTimeout(sid);
        }
    </script>
</head>
<body>
      <form>
           <input type="button" value="开始 ：" onclick="startT()">
           <input type="text" id="time">
           <input type="button" value="停止！" onclick="stopT()">
      </form>
      <script>
          var sad=self.setInterval("showTime()",500);
          function showTime() {
              var date=new Date();
              document.getElementById("clock").value=date.toString();
          }
      </script>
      <h3>现在的时间是：</h3>
      <input type="text" id="clock" size="60" >
<!--      //因为 JavaScript 代码较短，可以直接写在onclick时间里-->
      <button onclick="window.clearInterval(sad)">停止</button>
</body>
</html>